package com.htudata.flow.controller;

import com.htudata.common.enums.RequestSeqEnum;
import com.htudata.common.enums.RequestStatusEnum;
import com.htudata.common.vo.ResponseResult;
import com.htudata.core.util.ResultGenerator;
import com.htudata.flow.service.FlowShowService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
public class FlowController {

  @Autowired
  private FlowShowService flowShowService;
  
  @RequestMapping(value = {"/v1/live/givenFlowsAndNodes"}, method = {RequestMethod.GET})
  @ResponseBody
  public ResponseResult getGivenFlowsAndNodesOfUser(@RequestParam(required = true) long userId, @RequestParam(required = true) String a2) {
    try {
      return ResultGenerator.genResult(RequestSeqEnum.SEQ_000.getCode(), this.flowShowService
          .getGivenFlowsAndNodesOfUser(userId));
    } catch (Exception e) {
      log.error("getGivenFlowsAndNodesOfUser",e);
      return ResultGenerator.genErrorResult(RequestSeqEnum.SEQ_000.getCode(), RequestStatusEnum.STATUS_503
          .getCode(), "暂无数据");
    } 
  }
  
  @RequestMapping(value = {"/v1/live/resourceTree"}, method = {RequestMethod.GET})
  @ResponseBody
  public ResponseResult getResourceTree(@RequestParam(required = true) int resourceType, @RequestParam(required = false, defaultValue = "") String flowName, @RequestParam(required = false, defaultValue = "") String nodeName, @RequestParam(required = false, defaultValue = "") String triggerName, @RequestParam(required = true) String a2) {
    try {
      return ResultGenerator.genResult(RequestSeqEnum.SEQ_000.getCode(), this.flowShowService
          .getResourceTree(resourceType, flowName, nodeName, triggerName));
    } catch (Exception e) {
      log.error("getGivenFlowsAndNodesOfUser",e);
      return ResultGenerator.genErrorResult(RequestSeqEnum.SEQ_000.getCode(), RequestStatusEnum.STATUS_503
          .getCode(), "暂无数据");
    } 
  }
}
